import operator
from typing import TypedDict, Annotated, Optional, Any, List, Union, Literal, Dict

from langchain_core.messages import AnyMessage
from langgraph.graph import add_messages
from pydantic import BaseModel, Field


class ChoiceAPiState(TypedDict):
    api_messages: Annotated[List[AnyMessage], add_messages]
    analysis_model: Optional[str]
    urls: Annotated[List[Optional[str]], operator.add]
    datas: Annotated[List[Optional[TypedDict]], operator.add]
    targets: Annotated[List[Optional[List]], operator.add]
    results: Annotated[List[Optional[TypedDict]], operator.add]
    clear_results: Optional[TypedDict]
    error: Optional[str]
    tool_list: List[Optional[str]]
    rewrite_q: Optional[str]



# 提取时间实体返回结构
class ExtracDate(BaseModel):
    extrac_date_str: List[Optional[str]] = Field(default=None, description="描述时间的文字")
    format: Optional[str] = Field(default=None, description="提取时间文本转换为的时间格式")


# 标准时间返回结构
class StandardizeDate(BaseModel):
    start_date: Optional[str] = Field(default=None, description="开始时间")
    end_date: Optional[str] = Field(default=None, description="结束时间")


class RewriteText(BaseModel):
    rewrite_text: Optional[str] = Field(default=None, description="替换后的文本")


class JsonResponse(BaseModel):
    url: Optional[str] = Field(description="请求路径")
    data: Optional[TypedDict] = Field(description="请求参数")


class ColaTimeData(BaseModel):
    time: Union[Literal["NONETIME"], Dict[str, str]]


class TargetColumns(BaseModel):
    target_columns: List[str]

class InitRoute(BaseModel):
    next:  Literal['bingo'] | Literal['other']
